<?php
class Model_Filter extends Zend_Db_Table_Abstract{
	protected $_name = "filter";
	protected $_dependentTables = array("Model_CategoryFilter","Model_FilterValue");
	const SPEED = 1;
	const PAPER_SIZE = 2;  
	public function getFiltersByType($type){
		return  $this->fetchAll('type = '.$type);
	}
	public function getAllFilters(){
		return $this->fetchAll();
	}
	public function getFilterByID($id){
		return $this->find($id)->current();
	}
	public function createFilter($name){
		$filter = $this->createRow();
		$filter->name = $name;
		$filter->save();
		return $this->_db->lastInsertId();
	}
	public function updateFilter($id, $name){
		try{
			$this->update(array("name" => $name), 'id =' .$id);
			return true;
		}catch(Exception $ex){
			echo 'Caught exception: ',  $ex->getMessage(), "\n";
			return false;
		}
		
	}
	public function deleteFilter($id){
		if(is_numeric($id)){
			return $this->delete('id = '. $id);
		}else{
			return $this->delete('id in ('.$id.')');
		}
	}
	
}
?>